package com.chinanet.controller.faultanticipate;

import com.chinanet.annotation.JsonArg;
import com.chinanet.entry.faultanticipate.Branch;
import com.chinanet.entry.faultanticipate.Detail;
import com.chinanet.entry.faultanticipate.Model;
import com.chinanet.entry.faultanticipate.Record;
import com.chinanet.service.faultanticipate.IDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/details/manager")
public class DetailManagerController {

    @Autowired
    private IDetailService detailService;

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public long saveModel(@JsonArg("model") Model model, @JsonArg("detail") Detail detail, @JsonArg("branch") Branch branch) {
        return detailService.save(detail, model, branch);
    }

    @RequestMapping(value = "/update/branch", method = RequestMethod.POST)
    public long updateByBranch(@JsonArg("model") Model model, @JsonArg("detail") Detail detail, @JsonArg("branch") Branch branch, @JsonArg("lastBranch") Branch lastBranch) {
        return detailService.updateByBranch(detail, model, branch, lastBranch);
    }

    @RequestMapping(value = "/update/copy", method = RequestMethod.POST)
    public long updateByBranch(@JsonArg("record") Record record, @JsonArg("currentBranch") Branch currentBranch) {
        return detailService.updateByCopy(record, currentBranch);
    }
}
